package com.wsj.web.action.BmSite;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wsj.service.IBmClassTypeServ;
import com.wsj.service.IHomeSiteAdBannerDescriptServ;
import com.wsj.service.IHomeSiteAdBannerServ;
import com.wsj.service.IHomeSiteNewsClassServ;
import com.wsj.util.exception.BusinessException;
import com.wsj.util.page.PageResultSet;
import com.wsj.util.tool.FileUplaodAndManageForStorage;
import com.wsj.util.tool.RequestUtils;
import com.wsj.util.tool.StringUtils;
import com.wsj.web.constant.page.PageContent;
import com.wsj.web.form.BmSite.HomeSiteAdBannerExtBean;
import com.wsj.web.form.BmSite.HomeSiteAdBannerForm;
import com.wsj.web.vo.homeSite.BmClassType;
import com.wsj.web.vo.homeSite.HomeSiteAdBanner;
import com.wsj.web.vo.homeSite.HomeSiteAdBannerDescription;
import com.wsj.web.vo.homeSite.HomeSiteNewsClass;

public class HomeSiteAdBannerAction extends DispatchAction {

	private IHomeSiteAdBannerServ homeSiteAdBannerServ; 
	
	private IHomeSiteAdBannerDescriptServ homeSiteAdBannerDescriptServ; 
	
	private IHomeSiteNewsClassServ homeSiteNewsClassServ;
	
	private IBmClassTypeServ bmClassTypeServImpl;
	
	private FileUplaodAndManageForStorage imgUpload;

	/**
	 * 将指定的广告上移或下移，每次只移动一级
	 * type : 0 表示 向上，1 表示向下移动
	 * */
	public ActionForward move(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response){
		String topage = "bannerList";
		
		try {
			Integer desId = new Integer(0);
			Object adId = request.getParameter("id");
			Integer id = new Integer(0);
			if(adId != null){
				id = Integer.parseInt(adId.toString());
				HomeSiteAdBanner ad = this.homeSiteAdBannerServ.loadHsAdBannerById(id);
				Integer descriptId = ad.getHomeSiteAdBannerDescription().getId();
				HomeSiteAdBannerDescription adDes = this.homeSiteAdBannerDescriptServ.loadHsAdBannerById(descriptId);
				if(adDes != null){
					desId = adDes.getId();
				}
			}
			Object typeObj = request.getParameter("moveType");
			Integer move_type = new Integer(0);
			if(typeObj != null){
				move_type = Integer.parseInt(typeObj.toString());
			} 
			
			Boolean isOk = false; 
			isOk = this.homeSiteAdBannerServ.updateSequence(id, desId, move_type);
			if(isOk){
				if(move_type.equals(new Integer(0))){
					request.setAttribute("msg", "<script>alert('ID 为 "+id +" 的广告上移成功');</script>");
				}
				if(move_type.equals(new Integer(1))){
					request.setAttribute("msg", "<script>alert('ID 为 "+id +" 的广告下移成功');</script>");
				}
							
			}							
									
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		this.toBackPage(null,request);		
		return mapping.findForward(topage); 
	}
	
	/* 广告添加 第一步: */
	public ActionForward toAdd(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response){
		String topage = "banner_add";
		try {
			//  广告分类
			Integer typeId = this.getTypeId();
			
			//获取第一级分类下面的所有属于广告中的分类
			List firstClassList  = this.getHomeSiteNewsClassServ().loadFirstHomeSiteNewsClassByType(typeId);
			if(firstClassList == null || firstClassList.isEmpty())
			{
				firstClassList = new ArrayList();
			}
			request.setAttribute("firstHomeSiteNewsClassList",firstClassList);
			
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		
		return mapping.findForward(topage); 
	}
	
	
	/* 广告添加 第二步 */
	public ActionForward add(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response)
	{
		try {
			HomeSiteAdBannerForm hsForm = (HomeSiteAdBannerForm)form;
			request.setAttribute("hsForm", hsForm);
			HomeSiteAdBanner hs = new HomeSiteAdBanner();
			
			/*****
			 * 获取选中的分类id,取最小等级的
			 */
			hsForm = this.setSelectNewsClassId(hsForm);
			
			BeanUtils.copyProperties(hs, hsForm);
			
			// 图片上传
			if(hsForm.getPic()!=null&&!hsForm.getPic().getFileName().trim().equals("")){
				String uploadPath="fileUpload"+File.separator+"banner"+File.separator;
				imgUpload.setMyFiles(hsForm.getPic());
				imgUpload.setPath(uploadPath);

				String fileName = imgUpload.uploadFile(request, imgUpload.loadUploadFileName());
				if(fileName == null||fileName.equals("")){
					request.setAttribute("msg", "<script>alert('添加失败：文件格式错误，文件必须是 jpg,gif,jpeg格式的！');</script>");
					String url = "/admin/banner/bannerAction.do?action=toAdd";
					return new ActionForward(url);
				}				
				hs.setImg(fileName);				
			}
			
			/* 关联关系*/
			Long newsClassId = hsForm.getHsNewsClassId();
			HomeSiteNewsClass hsn = this.homeSiteNewsClassServ.loadNewsClassById(newsClassId);
			if(hsn != null){
				hs.setHomeSiteNewsClass(hsn);
			}
			
			Integer hsdId = hsForm.getHsDesId();
			HomeSiteAdBannerDescription hsd = this.homeSiteAdBannerDescriptServ.loadHsAdBannerById(hsdId);
			if(hsd!=null){
				hs.setHomeSiteAdBannerDescription(hsd);
			}
			
			this.homeSiteAdBannerServ.add(hs);
			request.setAttribute("msg","<script>alert('添加成功！');</script>");
			hs.setSequence(hs.getId());
			this.getHomeSiteAdBannerServ().update(hs);
						
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		
		return new ActionForward("/admin/banner/homeSiteAdBanner.do?action=toAdd");
	}
	
	

	/* 广告修改 第一步: */
	public ActionForward toUpdate(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response){
		String topage = "banner_update";
		String idStr = request.getParameter("id");
		
		
		String urlStr = RequestUtils.getRequestURL(request); 
		if(StringUtils.isNotNull(urlStr)){
			String parament = urlStr.substring(urlStr.indexOf("&"), urlStr.lastIndexOf("&"));
			if(StringUtils.isNotNull(parament)){
				request.setAttribute("parament", parament);
			}				
		}
		
		try {
			Integer id = Integer.parseInt(idStr);
			HomeSiteAdBanner hs = this.homeSiteAdBannerServ.loadHsAdBannerById(id);
			HomeSiteAdBannerExtBean hsExt = new HomeSiteAdBannerExtBean();
			BeanUtils.copyProperties(hsExt, hs);
			Long newsClassId = hs.getHomeSiteNewsClass().getId();
			HomeSiteNewsClass hsn = this.homeSiteNewsClassServ.loadNewsClassById(newsClassId);
			if(hsn != null)
			{
				hsExt.setHomeSiteNewsClass(hsn);
				hsExt.setClassName(hsn.getNames());
			}
			
			Integer hsdId = hs.getHomeSiteAdBannerDescription().getId();
			HomeSiteAdBannerDescription hsd = this.homeSiteAdBannerDescriptServ.loadHsAdBannerById(hsdId);
			if(hsd!=null){
				hsExt.setHomeSiteAdBannerDescription(hsd);
				hsExt.setPicName(hsd.getPicName());
			}
			
			String imgPath = hs.getImg();
			if(imgPath!=null && !imgPath.equals("")){
					request.setAttribute("imgPath", imgPath);
			}
			
			// 广告分类
			Integer typeId = this.getTypeId();
			
			// 获取第一级分类下面的所有属于广告中的分类
			List  firstClassList = this.getHomeSiteNewsClassServ().loadFirstHomeSiteNewsClassByType(typeId);
			if(firstClassList == null || firstClassList.isEmpty())
			{
				firstClassList = new ArrayList();
			}
			request.setAttribute("firstHomeSiteNewsClassList",firstClassList);
			
			//获得老的二级分类和三级分类
			this.loadOldNewsClass(request,hsExt);
			
			//描述id.
			List list = this.homeSiteAdBannerDescriptServ.loadByNewsClassId(hsExt.getHomeSiteNewsClass().getId());
			request.setAttribute("descriptList", list);
			request.setAttribute("bannerExtBean",hsExt);
			
						
		} catch (BusinessException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
		return mapping.findForward(topage); 
	}
	
	



	/* 广告修改 第二步: */
	public ActionForward update(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response){
		String topage = "bannerList";
		
		try {
			HomeSiteAdBannerForm hsForm = (HomeSiteAdBannerForm)form;
			Integer id = hsForm.getId();
			HomeSiteAdBanner hs = this.homeSiteAdBannerServ.loadHsAdBannerById(id);
			/*****
			 * 获取选中的分类id,取最小等级的
			 */
			hsForm.setSequence(hs.getId());
			hsForm = this.setSelectNewsClassId(hsForm);
			
			BeanUtils.copyProperties(hs, hsForm);
			hs.setTitle(hsForm.getTitles());
			//  如果 是否图片： 是 才下一步： 
			if(hsForm.getIsImg().equals(1)){
				if(null!=hsForm.getPic()){
					String name = hsForm.getPic().getFileName();
					if(!name.equals("")){
						String uploadPath="fileUpload"+File.separator+"banner"+File.separator;
						imgUpload.setMyFiles(hsForm.getPic());
						imgUpload.setPath(uploadPath);
						String oldFileName = hs.getImg();
						String fileName = "";
						// 若原来有图片，用原文件名字，替换掉
						if(oldFileName!=null && !oldFileName.equals("")){
							fileName = imgUpload.uploadFile(request, oldFileName);
						}else{
							fileName = imgUpload.uploadFile(request, imgUpload.loadUploadFileName());
						}
						if(fileName == null||fileName.equals("")){
							request.setAttribute("msg", "<script>alert('修改失败：文件格式错误，文件必须是 jpg,gif,jpeg格式的！')</script>");
							return mapping.findForward(topage); 
						}
						hs.setImg(fileName);						
					}
				}
			}			
			/* 关联关系*/
			Long newsClassId = hsForm.getHsNewsClassId();
			HomeSiteNewsClass hsn = this.homeSiteNewsClassServ.loadNewsClassById(newsClassId);
			if(hsn != null){
				hs.setHomeSiteNewsClass(hsn);
			}
			
			Integer hsdId = hsForm.getHsDesId();
			HomeSiteAdBannerDescription hsd = this.homeSiteAdBannerDescriptServ.loadHsAdBannerById(hsdId);
			if(hsd!=null){
				hs.setHomeSiteAdBannerDescription(hsd);
			}
			
			this.homeSiteAdBannerServ.update(hs);
			request.setAttribute("msg","<script>alert('id 为："+id+" 的广告，修改成功！');</script>");
			this.toBackPage(hsForm, request);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		
		
		return mapping.findForward(topage); 
	}
	
	
	public ActionForward delete(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response){
		String topage = "bannerList";
		
		String type = request.getParameter("type");
		if(StringUtils.isNotNull(type)){
			HomeSiteAdBanner hs = new HomeSiteAdBanner();
			try {
				String[] obj = request.getParameterValues("checkboxparam");  
				if(obj != null && obj.length > 0){
					for(int i=0;i<obj.length;i++){
						Integer id = Integer.parseInt(obj[i]);
						hs = this.homeSiteAdBannerServ.loadHsAdBannerById(id);
						if(hs!=null){
							this.homeSiteAdBannerServ.delete(hs);
						}
					}
				}			
								
				request.setAttribute("msg","<script>alert('删除成功！');</script>");
				
				this.toBackPage(null,request);
			} catch (BusinessException e) {
				e.printStackTrace();
			}
		}			
		
		return mapping.findForward(topage); 
	}
	
	
	public ActionForward list(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response){
		String topage = "bannerList";
		try {
			//  广告分类
			Integer typeId = this.getTypeId();
			
			//获取第一级分类下面的所有属于广告中的分类
			List firstClassList  = this.getHomeSiteNewsClassServ().loadFirstHomeSiteNewsClassByType(typeId);
			if(firstClassList == null || firstClassList.isEmpty())
			{
				firstClassList = new ArrayList();
			}
			request.setAttribute("firstHomeSiteNewsClassList",firstClassList);
			
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		
		this.loadPageList(null,null,null, null, null, null,new Integer(1),request);
		return mapping.findForward(topage); 
	}
	
	@SuppressWarnings("unchecked")
	public ActionForward search(ActionMapping mapping ,ActionForm form ,HttpServletRequest request,HttpServletResponse response) throws BusinessException{
		String topage = "bannerList";
		HomeSiteAdBannerForm hsForm = (HomeSiteAdBannerForm)form;
		
		this.toBackPage(hsForm, request);
		return mapping.findForward(topage); 
	}	
	
	
	
	
	
	
	//  整合参数，返回到上一页面
	@SuppressWarnings("unchecked")
	private void toBackPage(HomeSiteAdBannerForm hsForm,HttpServletRequest request){
		Integer page = new Integer(1);
		Long classId = null;
		String title = null;
		Integer hsDesId = null;
		Integer isImg = null;
		Short isLink = null;
		Short isJs = null;
		
		Long firstId = null;
		Long secondId = null;
		Long thirdId = null;
				
		try {
			if(request.getParameter("type") != null){
				String pageObj = request.getParameter("page");
				if(StringUtils.isNotNull(pageObj)){
					page = Integer.parseInt(pageObj);
				}
				String newsClassIdObj = request.getParameter("newsClassId");
				if(StringUtils.isNotNull(newsClassIdObj)){
					classId = Long.parseLong(newsClassIdObj);
				}
				String titleObj = request.getParameter("title");
				if(StringUtils.isNotNull(titleObj)){
					title = titleObj;
					title = new String(title.trim().getBytes("ISO-8859-1"),"UTF-8");
					
				}
				String hsDesIdObj = request.getParameter("hsDesId");
				if(StringUtils.isNotNull(hsDesIdObj)){
					hsDesId = Integer.parseInt(hsDesIdObj);
				}
				String firstIdObj = request.getParameter("firstId");
				if(StringUtils.isNotNull(firstIdObj)){
					firstId = Long.parseLong(firstIdObj);
				}
				String secondIdObj = request.getParameter("secondId");
				if(StringUtils.isNotNull(secondIdObj)){
					secondId = Long.parseLong(secondIdObj);
				}
				String thirdIdObj = request.getParameter("thirdId");
				if(StringUtils.isNotNull(thirdIdObj)){
					thirdId = Long.parseLong(thirdIdObj);
				}
				
			}else{
				if(hsForm != null){
					hsForm = this.setSelectNewsClassId(hsForm);
					page = hsForm.getPage();
					page = new Integer(1);
					classId = hsForm.getHsNewsClassId();
					title = hsForm.getTitle();
					hsDesId = hsForm.getHsDesId();
					firstId = hsForm.getFirstNewsClassId();
					secondId = hsForm.getSecondNewsClassId();
					thirdId = hsForm.getThirdNewsClassId();
				}			
			}
			
			
			if(thirdId != null && !thirdId.equals(new Long(-1))){
				classId = thirdId;
			}
			else if(secondId != null && !secondId.equals(new Long(-1))){
					classId = secondId;
			}else if(firstId != null && !firstId.equals(new Long(-1))){
						classId = firstId;
			}
			if(secondId != null && !secondId.equals(new Long(-1))){
				//		  三级分类
				Map<Long,String> thirdNewsClassList = new HashMap<Long, String>();
				thirdNewsClassList = this.secondNewsClassListByFirstClassId(secondId);
				if(thirdNewsClassList.size()>0){
					request.setAttribute("thirdNewsClassList", thirdNewsClassList);						
				}
			}
			if(firstId != null && !firstId.equals(new Long(-1))){
				//		  二级分类
				Map<Long,String> secondNewsClassList = new HashMap<Long, String>();
				secondNewsClassList = this.secondNewsClassListByFirstClassId(firstId);
				if(secondNewsClassList.size()>0){
					request.setAttribute("secondNewsClassList", secondNewsClassList);						
				}
			}
			
			// 广告分类
			Integer typeId = this.getTypeId();
			//获取第一级分类下面的所有属于广告中的分类
			List firstClassList  = this.getHomeSiteNewsClassServ().loadFirstHomeSiteNewsClassByType(typeId);
			if(firstClassList == null || firstClassList.isEmpty())
			{
				firstClassList = new ArrayList();
			}
			request.setAttribute("firstHomeSiteNewsClassList",firstClassList);
			
			// 根据分类获取广告描述ID
			if(classId != null && !new Long(-1).equals(classId)){
				List<HomeSiteAdBannerDescription> des_list = this.homeSiteAdBannerDescriptServ.loadByNewsClassId(classId);
				if(StringUtils.isNotNull(des_list)){
					request.setAttribute("hsDesList", des_list);
				}
				
			}	
			if(hsDesId != null && !hsDesId.equals(new Integer(-1))){
			    request.setAttribute("hsDesId", hsDesId); // 广告描述ID
			}else{
				hsDesId = null;
			}
			
			if(new Long(-1).equals(classId)){
				hsForm.setHsNewsClassId(null);
			}
			
			
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		request.setAttribute("hsForm", hsForm);
		request.setAttribute("thirdId", thirdId); //  一级分类ID
		request.setAttribute("secondId", secondId); //  二级分类ID
		request.setAttribute("firstId", firstId);  //  三级分类ID
	      request.setAttribute("hsDesId", hsDesId);
	      //  广告标题
	      request.setAttribute("title", title);
		this.loadPageList(classId,hsDesId,title,isImg,isLink,isJs,page,request);
	}
	

	/******
	 * 获取选中的最小的分类id
	 * @param hsForm
	 * @return
	 */
	private HomeSiteAdBannerForm setSelectNewsClassId(HomeSiteAdBannerForm hsForm) 
	{
		Long selectClassId=null;
		
		 if(hsForm.getThirdNewsClassId()!=null && hsForm.getThirdNewsClassId().intValue()!=-1)
		{
			selectClassId = hsForm.getThirdNewsClassId();
		}
		else if(hsForm.getSecondNewsClassId()!=null && hsForm.getSecondNewsClassId().intValue()!=-1 )
		{
			selectClassId = hsForm.getSecondNewsClassId();
		}
		else if(hsForm.getFirstNewsClassId()!=null && hsForm.getFirstNewsClassId().intValue()!=-1 )
		{
			selectClassId = hsForm.getFirstNewsClassId();
		}
		hsForm.setHsNewsClassId(selectClassId);
		
		return hsForm;
		
	}

	
	
	/* 广告标题、是否图片、外部链接、是否JS、 */
	private  void loadPageList(Long newsClassId,Integer hsDesId,String title,Integer isImg,Short isLink,Short isJs,Integer page,HttpServletRequest request)
	{
		 try {
			  //获取参数
			  int pageSize=10;			  		 
			  
			  PageResultSet pageResultSet = this.homeSiteAdBannerServ.loadPageList(newsClassId,hsDesId, title, isImg, isLink, isJs, page, pageSize);
			  if(pageResultSet!=null)
			  {
			      //设置上一页
			      request.setAttribute(PageContent.backPage,pageResultSet.getBackPage());
			      //下一页
			      request.setAttribute(PageContent.nextPage,pageResultSet.getNextPage());
			      //当前页
			      request.setAttribute(PageContent.curPage,pageResultSet.getCurPage());
			      //总共页数
			      request.setAttribute(PageContent.allPage,pageResultSet.getAllPage());
			      request.setAttribute(PageContent.page, page);
			      request.setAttribute(PageContent.pageSize, pageResultSet.getPageSize());
			      //总记录数
			      request.setAttribute(PageContent.recordNum,pageResultSet.getRecordNum());
			      //开始行码
			      request.setAttribute(PageContent.startRow,pageResultSet.getStartRow());
			      //结束行码
			      request.setAttribute(PageContent.endRow,pageResultSet.getEndRow());
			      List li=pageResultSet.getResult();
			      
			      // 栏目显示
			      
			      List<HomeSiteAdBannerExtBean> liExt = new ArrayList<HomeSiteAdBannerExtBean>();
			      for(int i=0;i<li.size();i++){
			    	  HomeSiteAdBanner hs = new HomeSiteAdBanner();
				      HomeSiteAdBannerExtBean hsExt = new HomeSiteAdBannerExtBean();	
			    	  hs = (HomeSiteAdBanner)li.get(i);
			    	  Long claId = hs.getHomeSiteNewsClass().getId();
					  HomeSiteNewsClass hsn = this.homeSiteNewsClassServ.loadNewsClassById(claId);
					  if(hsn != null){
							hsExt.setClassName(hsn.getNames());
					  }
					  BeanUtils.copyProperties(hsExt, hs);
			    	  liExt.add(hsExt);
			      }
			      
			      request.setAttribute("bannerList",liExt);
			      
			  }
			  
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (BusinessException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
          
	}
	
	/******
	 * 获得老的二级分类,
	 * @param request
	 * @param hs
	 */
	private void loadOldNewsClass(HttpServletRequest request, HomeSiteAdBannerExtBean hs)
	{
		Long newsClassId = hs.getHomeSiteNewsClass().getId();
	    
		//获取
		try {
			//获得分类
			HomeSiteNewsClass  homeSiteNewsClass =this.getHomeSiteNewsClassServ().loadNewsClassById(newsClassId);
			String seq=homeSiteNewsClass.getSeq();
			
			//一级分类id
			String firstNewsClassId="";
			//二级分类id
			String secondNewsClassId="";
			//三级分类id
			String thirdNewsClassId="";
			
			Map<Long, String> secondNewsClassMap = new HashMap<Long, String>();
			
			Map<Long, String> thirdNewsClassMap = new HashMap<Long, String>();
			
			if(seq!=null  && !seq.equals(""))
			{
				if(seq.indexOf(",")!=-1)
				{
				   String[] param=seq.split(",");
				   //获得第一级分类列表
				   if(param.length>=3)
				   {
					   firstNewsClassId = param[2];
				   }
				   
				   //获得第二级的分类列表
				   if(param.length>=4)
				   {
					     secondNewsClassId = param[3];
				   }
				   
				   //获得第三级的分类列表
				   if(param.length>=5)
				   {
					   thirdNewsClassId = param[4];
				   }
				}
			}
			
		
		//通过一级分类id,获取二级分类列表
			if(firstNewsClassId!=null  && !firstNewsClassId.equals(""))
			{
				hs.setFirstNewsClassId(Long.valueOf(firstNewsClassId));
				secondNewsClassMap = this.secondNewsClassListByFirstClassId(Long.valueOf(firstNewsClassId));
			}
			
			//通过二级分类id,获取三级分类的广告列表
			if(secondNewsClassId!=null   && !secondNewsClassId.equals(""))
			{
				hs.setSecondNewsClassId(Long.valueOf(secondNewsClassId));
				thirdNewsClassMap = this.thirdNewsClassListByFirstClassId(Long.valueOf(secondNewsClassId));
			}
			
			//如果三级分类存在,则设置三级分类
			if(thirdNewsClassId!=null  && !thirdNewsClassId.equals(""))
			{
				hs.setSecondNewsClassId(Long.valueOf(thirdNewsClassId));
			}
			
			
			request.setAttribute("secondHomeSiteNewsClassList",secondNewsClassMap );
			
			request.setAttribute("thirdHomeSiteNewsClassList",thirdNewsClassMap);
			
			
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		
	}




	/*****
	 * 通过一级分类id加载二级分类下面的分类列表
	 * @param parenId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	private Map<Long, String> thirdNewsClassListByFirstClassId(Long parenId) 
	{
		  try {
			return  this.getHomeSiteNewsClassServ().loadSecondHomeSiteNewsClassByAdType(parenId);
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		
		return new HashMap();
	}


	/*****
	 * 通过二级分类id,加载二级分类下面的分类列表
	 * @param parenId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	private Map<Long, String> secondNewsClassListByFirstClassId(Long parenId) 
	{
		  try {
				return  this.getHomeSiteNewsClassServ().loadSecondHomeSiteNewsClassByAdType(parenId);
			} catch (BusinessException e) {
				e.printStackTrace();
			}
			
			return new HashMap();
	}
	
	private Integer getTypeId() throws BusinessException{
		//	  广告分类
		Integer typeId = 0;
		BmClassType bmt = this.bmClassTypeServImpl.getBmClassTypeByClassTypeName("广告类别");
		if(bmt!=null){
			typeId = bmt.getId();
		}
		return typeId;
	}
	
	public IHomeSiteAdBannerServ getHomeSiteAdBannerServ() {
		return homeSiteAdBannerServ;
	}


	public void setHomeSiteAdBannerServ(IHomeSiteAdBannerServ homeSiteAdBannerServ) {
		this.homeSiteAdBannerServ = homeSiteAdBannerServ;
	}


	public IHomeSiteAdBannerDescriptServ getHomeSiteAdBannerDescriptServ() {
		return homeSiteAdBannerDescriptServ;
	}


	public void setHomeSiteAdBannerDescriptServ(
			IHomeSiteAdBannerDescriptServ homeSiteAdBannerDescriptServ) {
		this.homeSiteAdBannerDescriptServ = homeSiteAdBannerDescriptServ;
	}


	public IHomeSiteNewsClassServ getHomeSiteNewsClassServ() {
		return homeSiteNewsClassServ;
	}


	public void setHomeSiteNewsClassServ(
			IHomeSiteNewsClassServ homeSiteNewsClassServ) {
		this.homeSiteNewsClassServ = homeSiteNewsClassServ;
	}

	public FileUplaodAndManageForStorage getImgUpload() {
		return imgUpload;
	}


	public void setImgUpload(FileUplaodAndManageForStorage imgUpload) {
		this.imgUpload = imgUpload;
	}


	public IBmClassTypeServ getBmClassTypeServImpl() {
		return bmClassTypeServImpl;
	}


	public void setBmClassTypeServImpl(IBmClassTypeServ bmClassTypeServImpl) {
		this.bmClassTypeServImpl = bmClassTypeServImpl;
	}

}
